package com.wholeintech.ble;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.wholeintech.wirednet.WiredNetService;
import com.wholeintech.zigbee.gw.ZigBeeService;
import com.wholeintech.utils.CommonIntent;

public class MyBootReceiver extends BroadcastReceiver {
    public MyBootReceiver() {
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO: This method is called when the BroadcastReceiver is receiving
        final String TAG = "MyBootReceiver";
        String action = intent.getAction();
        if (action.equals(Intent.ACTION_BOOT_COMPLETED))
        {       	
        	intent = new Intent(context, ZigBeeService.class);
            context.startService(intent);           
            intent = new Intent(context, BleService.class);
            context.startService(intent);          
            intent = new Intent(context, WiredNetService.class);
            context.startService(intent);           
            Log.d(TAG,"System boot complete");  
        } else if( action.equals(CommonIntent.ACTION_HWSERVICE_RESTART)){
           try{
	        	intent = new Intent(context, ZigBeeService.class);
	            context.stopService(intent);
	            Thread.sleep(200);
	            context.startService(intent);     
	            
	            //intent = new Intent(context,MyBleService.class);
	            //context.stopService(intent);
	            //Thread.sleep(200);
	            //context.startService(intent);  
	            
	            //intent = new Intent(context, WiredNetService.class);
	           // context.stopService(intent);
	            //Thread.sleep(200);
	            //context.startService(intent);           
	            Log.d(TAG,"HwService restart");     
	            
	        } catch (Exception e) {
	            Log.e(TAG, "write  data IOException" + e);
	        } 
        	
        }
    }
}
